import matplotlib.pyplot as plt
import numpy as np
import math

t = np.linspace(0, 2 * math.pi, 1001)
xt = []
yt = []
sqr3 = math.sqrt(3)
for s in t:
    xs = sqr3 * math.sin(s)
    ys = 2.0 / 3.0 * (math.sqrt(math.fabs(xs)) + sqr3 * math.cos(s))
    xt.append(xs)
    yt.append(ys)

plt.figure()
plt.plot(xt, yt, label = "curve")

filename = "data/proE.txt"
with open(filename, 'r') as f:
    lines = f.readlines()

N = [10, 40, 160]
for i in range(3):
    x = [float(s) for s in lines[2 * i].split()]
    y = [float(s) for s in lines[2 * i + 1].split()]
    plt.plot(x, y, label = "N = " + str(N[i]), linestyle = "--")

plt.xlabel("x")
plt.ylabel("y")
plt.title("Heart Cruve.")
plt.legend()
figurename = "../report/figure/ProE.png"
plt.savefig(figurename)
print("Finish ploting for Pro E.")